import $ from 'jquery';

class UIStore {
    _zoomIn;
    _zoomOut;
    _setHeight;
    _setWidth;
    _generateModel;
    _update3Dmodel;

    zoomIn = () => {
        if (this._zoomIn) {
            this._zoomIn();
            return;
        }

        console.log('zoomIn');
    }

    zoomOut = () => {
        if (this._zoomOut) {
            this._zoomOut();
            return;
        }

        console.log('zoomOut');
    }

    setHeight = (height) => {
        if (this._setHeight) {
            this._setHeight(height);
            return;
        }

        console.log('height', height);
    }

    setWidth = (width) => {
        if (this._setWidth) {
            this._setWidth(width);
            return;
        }

        console.log('width', width);
    }

    generateModel = () => {
        console.log('generateModel');
        let points = JSON.parse(localStorage.getItem('points'));

        return $.ajax({
            type: 'POST',
            url: '/api/3Dmodel',
            data: JSON.stringify(points)
        }).then((payload) => {
            if (payload.status === 'success') {
                // TODO update model
                console.log("update 3d model");
                this.update3Dmodel();
            }
            return payload;
        });
    }

    update3Dmodel = () => {
        if (this._update3Dmodel) {
            this._update3Dmodel();
            return;
        }

        console.log('update3Dmodel');
    }
}

export default new UIStore();
